
import request from "../request";

const HEAD = "/home/category/head"

export function navtext() {
  return request({
    url: HEAD,
    method: 'get'
  })
}


export function classify() {
  return request({
    url: '/home/brand',
    method: 'get',
  })
}


export function swiper() {
  return request({
    url: '/home/banner',
    method: 'get',
  })
}


export function newthing() {
  return request({
    url: '/home/new',
    method: 'get',
  })
}

export function renqi() {
  return request({
    url: '/home/hot',
    method: 'get',
  })
}


export function remen() {
  return request({
    url: '/home/brand',
    method: 'get',
  })
}


export function jujias() {
  return request({
    url: '/home/goods',
    method: 'get',
  })
}



export function zuixin() {
  return request({
    url: '/home/special',
    method: 'get',
  })
}



export function catelist(id) {
  return request({
    url: '/category',
    method: 'get',
    params: { id }
  })
}

 
/*
    二级分类筛选数据是api
*/
export function cateFilter(id) {
  // console.log(id);
  return request({
    url: "/category/sub/filter",
    method: "get",
    params: { id }
  });
}


export function getGoods(params) {
  // console.log(id);
  return request({
    url: "/category/goods/temporary",
    method: "post",
    data: params
  });
}

//获取当前商品的详情信息
export function getdetail(id) {
  // console.log(id);
  return request({
    url: "/goods",
    method: "get",
    params: { id }
  });
}

export function findRelGoods(id, limit = 16) {
  return request({
    url: '/goods/relevant',
    method: 'get',
    params: { id, limit }
  }
  )
}

/*
    热销数据是api
*/

export function gethot(limit = 3) {
  return request({
    url: "/goods/hot",
    method: "get",
    params: { limit },
  });
}

//评价头部
export const findCommentInfoByGoods = (id) => {
  return request(`/goods/${id}/evaluate`)
}
//评价分页数据  /goods/:id/evaluate/page
export function findCommentListByGoods(id){
  return request({
    url:`/goods/${id}/evaluate/page`,
    method: "get",
  })
}


//账号和密码的登录
export function login(account,password){
  return request({
    url:"/login",
    method: "post",
    data:{account,password}
  })
}

//qq登录
export function qqlogin(unionId,source=6){
  return request({
    url:"/login/social",
    method: "post",
    data:{unionId,source}
  })
}

//第三方验证码发送
export function sendcode(mobile,unionId ,source=6){
  return request({
    url:'/login/social/code?mobile='+mobile,
    method: "get",
    params:{unionId,source}
  })
}

//第三方登录有账号没绑定
export function bendtel(mobile,unionId ,code){
  return request({
    url:'/login/social/bind',
    method: "post",
    data:{unionId,mobile,code}
  })
}

//第三方登录的完善信息
export function complete(unionId,account ,mobile,code,password){
  return request({
    url: `/login/social/${unionId}/complement`,
    method: "post",
    data:{account ,mobile,code,password}
  })
}

//合并数据
export function mergecart(arr){
  return request({
    url: "/member/cart/merge",
    method: "post",
    data:arr
  })
}
//请求购物车的数据
export function cartlist(){
  return request({
    url: "/member/cart",
    method: "get",
  })
}

//删除购物车的数据
export function cartdel(ids,clearAll=false,clearInvalid=false){
  return request({
    url: "/member/cart",
    method: "delete",
    data:{ids,clearAll,clearInvalid}
  })
}
//线上购物车数据的添加
export function cartadd(skuId,count){
  return request({
    url: "/member/cart",
    method: "post",
    data:{skuId,count}
  })
}

//全选反选

export function quanxuan(selected=true,ids){
  return request({
    url: "/member/cart/selected",
    method: "put",
    data:{selected,ids}
  })
}
//地址
export function addresslist(){
  return request({
    url: "/member/address",
    method: "get" 
  })
}

//添加地址
export function addlists(obj){
  return request({
    url: "/member/address",
    method: "post",
    data:obj
  })
}